<template>
    <div>
        <h1>病房信息显示</h1>
        <a href="/addbf">病房信息添加</a>
        <br>
        <a href="/showks">科室信息显示</a>
<br>
 <a href="/showys">医生信息显示</a>
<br>
    病房名称:
        <input type="text" v-model="page.bfname" placeholder="病房名称">
        科室:
        <select v-model="page.ksid">
            <option :value="0">请选择科室</option>
            <option v-for="e in ksxlk" :value="e.id">{{ e.ksName }}</option>
        </select>
        <input type="button" value="查询" @click="chax">
         <input type="button" value="清空" @click="qk">
        
        <table class="table"> 
            <thead>
                <tr>
                    <td>病房编号</td>
                    <td>病房号</td>
                    <td>所属科室</td>
                    <td>床位总数量</td>
                    <td>病房状态</td>
                    <td>空闲床数量</td>
                    <td>创建日期</td>
                    <td>床铺状态</td>
                    <td>修改病房状态</td>
                </tr>
            </thead>
            <tbody>
                 <tr v-for="e in data">
                    <td>{{ e.id }}</td>
                    <td>{{ e.houseName }}</td>
                    <td>{{ e.ksName }}</td>
                    <td>{{ e.houseZS }}</td>
                    <td>{{ e.isState?'维修':'启用' }}</td>
                    <td>{{ e.houseKC }}</td>
                    <td>{{ moment(e.houseBFDate).format("YYYY-MM-DD") }}</td>
                    <td>{{ e.cpState?'未满':'已住满' }}</td>
                    <td>
                        <input type="button" :value="e.isState?'启用':'维修'" @click="upstate(e.id)">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref,onMounted} from 'vue'
import axios from 'axios'
import { useRouter } from 'vue-router'
import moment  from 'moment';
import {useUserStore} from '../../stores/user'

const user = useUserStore();
const router=useRouter();

onMounted(()=>{

    if(user.Userinfo.name=="")
{
    alert("你还没登录,请先登录")
    router.push({path:"/login"})
}
 KSXLKS();
    show();
})
const chax=()=>{
   
    show();
}
//修改状态
const upstate=(val:any)=>{
     if(!confirm("确认修改状态吗"))
{
    return;
}
    axios.get("/api/HouseBF/UpState",{params:{id:val}}).then(res=>{
        if(res.data>0)
    {
        alert("修改状态成功");
        show();
    }
    else{
        alert("修改状态失败");
        return;
    }
    })
}

//科室下拉框
const ksxlk=ref([{
    "id": 0,
    "ksName": "",
    "kScount": 15,
    "ksms": "",
    "ksDate": "2025-05-30T00:00:00",
    "isDelete": true
}]) 
const KSXLKS=()=>{
    axios.get("/api/HouseKS/XLKks").then(res=>{
        ksxlk.value=res.data
    })
} 

const data=ref([{
    "id": 1,
    "houseName": "string",
    "houseZS": 0,
    "houseKC": 0,
    "houseBFDate": "2025-05-19T01:59:09.048",
    "isState": false,
    "cpState": true,
    "ksid": 1,
    "ksName": "骨科"
  }])

const qk=()=>{
    page.value.bfname="";
    page.value.ksid=0;
}

const page=ref({
    bfname:"",
    ksid:0,
})

const show=()=>{
    axios.get("/api/HouseBF/ShowBF",{params:page.value}).then(res=>{
        data.value=res.data
    })
}


</script>

<style scoped>

</style>    